<?php

class CarsController extends Zend_Controller_Action
{

    public function init()
    {
        
        $core = new Model_Core();
        $this->view->getcontroller = Zend_Controller_Front::getInstance()->getRequest()->getControllerName();
        $this->view->getaction = Zend_Controller_Front::getInstance()->getRequest()->getActionName();
        
        $city_arr = $this->getCityarr();
        $this->view->putcity = $city_arr[city_name];
        $this->view->putcity_id = $city_arr[city_id];
        //城市列表   用于底部 切换城市 已使用AJAX
        $all_city = new Model_City();
        $this->view->all_city = $all_city->getAllCity();
        
        $carmodel = new Model_CarModel();
        $this->view->allbrand = $carmodel->getAllBrand();
        
        
        
        //USE AJAX TO LOGIN ACCOUNT?
        if ($core->isLogin()){
        	$this->view->member = $core->isLogin();
        }
        $this->view->ref = urlencode("http://".$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]);
        
        
        $this->view->nowtitle = "车型大全";
        $this->_helper->layout->setLayout('buy');
        
        $this->view->headTitle("车型大全", 'PREPEND');
    }
    
    protected function getCityarr(){
    	$core = new Model_Core();
    	$city_id = intval($this->_request->getParam('city_id'));
    	$ip = $_SERVER['REMOTE_ADDR'];
    	$city_arr = $core->getNowCity($city_id, $ip);
    	return $city_arr;
    }
    
    public function indexAction() {
    	
        Header( "HTTP/1.1 302 Moved Permanently" );
        $this->_redirect('/');
    }

    
    
    public function detailAction()
    {
        $id = intval($this->_request->getParam('id'));
        $detail = new Model_CarDetailtb();
     
        $data = $detail->getAlldetail($id);
        
        $this->view->data = $data;
        
        $name = $data[0][deploy_value];
        $this->view->name = $name;
        
        $this->view->id = $id;
        
        $nav = "<li><span class=\"divider\">/</span><a href=\"".$this->view->url(array('controller'=>'cars','action'=>'index'),null,true)."\">车型大全</a> </li>";
        $nav .= "<li><span class=\"divider\">/</span><a href=\"".$this->view->url(array('controller'=>'cars','action'=>'detail','id'=>$id),null,true)."\">".$name."</a> </li>";
        
        $this->view->nav = $nav;
        
        $this->view->headTitle($name." 详细配置", 'PREPEND');
        $this->view->headMeta()->setName('keywords', $name.'配置信息');
        $this->view->headMeta()->setName('description', $name."详细配置信息");
    }


}

